package com.bdqn.ch02.repository;

import com.bdqn.ch02.entity.User;
import com.bdqn.ch02.vo.UserInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Map;

public interface UserRepository extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {

    public List<User> findByUsrName(String usrName);

    //public List<User> findByUsrNameAndUsrRoleIdAndUsrFlag(String usrName, Long usrRoleId, Integer usrFlag);

    @Query("select u from User u where u.role.roleId=?1")
    public List<User> findByRoleId(Long roleId);

    @Query("select u from User u where u.role.roleId=?1")
    public Page<User> findPageByUsrRoleId(Long roleId, Pageable pageable);

/*    @Query("select u.usrId as usrId, u.usrName as usrName, u.usrPassword as usrPassword,u.usrRoleId as usrRoleId, u.usrFlag as usrFlag, r.roleName as roleName from User u, Role r where u.usrRoleId=r.roleId and u.usrId=?1")
    public UserInfo getUserInfo(Long usrId);*/


    //sql  结构化查询语言
    //hql  hibernate query language查询语言
    @Transactional
    @Modifying
    @Query(value = "delete from sys_user where usr_id=?1",nativeQuery = true)
    public void deleteSqlUserId(Long id);

}
